Skip to content

[General] [Fixed] - Fix stale leadingItem/trailingItem in VirtualizedSectionList ItemWithSeparator#56363

Open
Nedunchezhiyan-M wants to merge 1 commit into
react:mainfrom
Nedunchezhiyan-M:fix/virtualizedsectionlist-itemwithseparator-stale-state
Open

[General] [Fixed] - Fix stale leadingItem/trailingItem in VirtualizedSectionList ItemWithSeparator#56363
Nedunchezhiyan-M wants to merge 1 commit into
react:mainfrom
Nedunchezhiyan-M:fix/virtualizedsectionlist-itemwithseparator-stale-state

Conversation

@Nedunchezhiyan-M

Copy link
Copy Markdown
Contributor

Summary:

ItemWithSeparator in VirtualizedSectionList stores separator props (leadingSeparatorProps, separatorProps) in local React state, initialised once from the incoming props.leadingItem, props.item, and props.trailingItem. However, the virtualised list can recycle the same component instance for a different data row when the rendered region changes (e.g. after scrolling). When this happens the component re-renders with new item/section props, but the state is never updated, so the ItemSeparatorComponent receives stale values from the previous row — including undefined at section boundaries.

This was reproducible via the failing test added in #55707.

Fix: Add a useEffect that resets both separator prop objects whenever the relevant item or section props change, keeping the state in sync without affecting the separate useEffect that registers the highlight/updateProps callbacks.

Fixes #55708

Changelog:

[General] [Fixed] - Fix VirtualizedSectionList passing stale leadingItem/trailingItem to ItemSeparatorComponent after cell reuse

Test Plan:

The existing failing test in #55707 (VirtualizedSectionList › syncs ItemWithSeparator separator props when list re-renders with new leadingItem/trailingItem) should now pass with this fix applied.

The effect runs whenever props.item, props.leadingItem, props.leadingSection, props.section, props.trailingItem, or props.trailingSection change — exactly the props that seed the separator state on mount.

…reused

ItemWithSeparator stores leadingSeparatorProps and separatorProps in local
state, initialised once from the incoming props. When the virtualised list
recycles the same cell component for a different data row (e.g. after
scrolling), the component re-renders with new item/section props but the
state is never updated, so the separator keeps the stale values from the
previous row. This can expose undefined leadingItem or trailingItem values
at section boundaries, as reported in react#55708.

The fix adds a useEffect that resets both separator prop objects whenever
any of the relevant incoming props change, keeping the state in sync with
the current row without disturbing any external highlight/updateProps calls
that happen in the separate useEffect below.
@meta-cla

meta-cla Bot commented Apr 8, 2026

Copy link
Copy Markdown

Hi @Nedunchezhiyan-M!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@Nedunchezhiyan-M Nedunchezhiyan-M force-pushed the fix/virtualizedsectionlist-itemwithseparator-stale-state branch from 39f8d8c to c745ae3 Compare April 8, 2026 19:59
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 10, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VirtualizedSectionList passes incorrect leading/trailingItem to ItemSeparatorComponent

1 participant